//
//  DrugsViewModel.swift
//  EyeVisionForDoctors
//
//  Created by PMC on 2020/3/1.
//  Copyright © 2020 tao Tao. All rights reserved.
//

import Foundation
import HandyJSON

struct DrugsModel: HandyJSON {
    /// 数量
    var drugNumber: String?
    /// 使用频次
    var drugFrequency: String?
    /// 用法 eg：口服
    var drugChannel: String?
    /// 药品id
    var westernId: String?
    var drugDose: String?
    
    /// 药品id
    var id: String?
    /// 药品名称
    var name: String?
    /// 生产厂家
    var manufacturer: String?
    /// 药品规格
    var drugSpecification: String?
    /// 用法
    var drugUsing: String?
    /// 剂量单位
    var dosageUnit: String?
    /// 药品单价
    var expense: String?
    var totalExpense: String?
    
    /// 售价
    var outPrice: String?
    ///药品h5链接
    var instructionUrl: String?
}

struct DrugsViewModel {
    
    let models: [DrugsModel]
    
    var numberOfRows: Int { return models.count }
    
    func viewModel(for indexPath: IndexPath) -> DrugsRowViewModel {
        return DrugsRowViewModel(model: models[indexPath.row])
    }
}

struct DrugsRowViewModel {
    let model: DrugsModel
    
    init(model: DrugsModel) {
        self.model = model
        
        self.westernId = model.westernId ?? ""
        self.drugNumber = model.drugNumber ?? ""
        self.drugFrequency = model.drugFrequency ?? ""
        self.drugChannel = model.drugChannel ?? ""
        self.drugDose = model.drugDose ?? ""
        
        self.name = model.name ?? ""
        
        self.id = model.id ?? ""
        self.drugFacturer = model.manufacturer ?? ""
        self.drugSpecification = model.drugSpecification ?? ""
        self.drugUsing = model.drugUsing ?? ""
        
        self.dosageUnit = model.dosageUnit ?? ""
        self.expense = model.expense ?? ""
        self.totalExpense = model.totalExpense ?? ""
        self.instructionUrl = model.instructionUrl  ?? ""
    }
    
    ///H5链接
    var instructionUrl: String?
    /// 数量
    var drugNumber: String
    /// 使用频率 例如：1天1次，1天3次
    var drugFrequency: String
    /// 用药方式 如：口服
    var drugChannel: String
    /// 处方中的药品id
    var westernId: String
    /// 剂量  一次的使用量
    var drugDose: String
    /// 药品名称
    var name: String
    
    var id: String
    /// 生产厂家
    var drugFacturer: String
    /// 药品规格
    var drugSpecification: String
    /// 用法
    var drugUsing: String
    
    /// 剂量单位
    var dosageUnit: String
    /// 药品单价
    var expense: String
    /// 药品总价
    var totalExpense: String
}
